package com.xbb.init;

import com.xbb.constant.PathConstant;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "", loadOnStartup = 1) // 随应用启动加载
public class InitServlet extends HttpServlet {

    /**
     * @description: 初始化加载路径
     * @param config
     * @return: void
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        PathConstant.CONTEXT_PATH = config.getServletContext().getContextPath() + "/"; // contextPath
        PathConstant.WEB_FILE_ROOT = config.getServletContext().getRealPath("/"); // webFileRoot
        PathConstant.FILE_STORAGE_ROOT = PathConstant.WEB_FILE_ROOT + "file/";
        PathConstant.IMG_STORAGE_ROOT = PathConstant.WEB_FILE_ROOT + "images/";
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("/login.html");
    }

}
